define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        fieldlog: function() {
            Table.api.init({
                extend: {
                    index_url: 'project_check/fieldlog' + location.search,
                    // add_url: 'project_checklog/add',
                    edit_url: 'project_check/edit',
                    // del_url: 'project_checklog/del',
                    // multi_url: 'project_checklog/multi',
                    table: 'project_check',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                showExport: false,
                showToggle: false,
                showColumns: false,
                commonSearch: true,
                searchFormVisible: true,
                showSearch: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'project_name', title: __('项目名称'),operate:false},
                        {field: 'operator_nickname', title: __('操作人'), operate:false},
                        // {field: 'operate_field_label', title: __('操作字段名'),operate:false},
                        {field: 'old_content', title: __('原始值'), operate:'like'},
                        {field: 'new_content', title: __('修改值'), operate:'like'},
                        // {field: 'demo', title: __('备注'), operate:false,table: table, 
                        //     buttons: [
                        //         {
                        //             name: 'dispatch',
                        //             text: ' 备 注',
                        //             icon: ' fa fa-pencil',
                        //             title: ' 备 注',
                        //             classname: 'btn btn-xs btn-success btn-dialog',
                        //             url: 'project_check/demo',
                        //         }
                        //     ],
                        //     formatter: function (value, row, index){
                        //         if(!row.demo)
                        //             return Table.api.formatter.buttons.call(this, value, row, index);  
                        //         else
                        //             return row.demo;
                        //     },
                        // },
                        {field: 'demo', title: __('备注'), operate:false},
                        {field: 'demo_pic', title: __('图片'), operate:false,table: table, events: Table.api.events.operate, formatter: function (value, row, s){
                                if(row.demo_pic){
                                    return '<a href="'+row.demo_pic+'" target="_blank"><i class="fa fa-photo"><i></a>';
                                }else{
                                    return ''
                                }
                                return Table.api.formatter.operate.call(this, value, row, s);
                            }
                        },
                        {field: 'create_time', title: __('操作时间'), operate:'RANGE', addclass:'datetimerange', formatter:Table.api.formatter.datetime,datetimeFormat:'YYYY-MM-DD'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        demo:function()
        {
           Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});